package components
{
	import flash.events.MouseEvent;
	
	import mx.controls.Button;
	import mx.controls.Label;
	import mx.controls.TextArea;
	import mx.events.ResizeEvent;
	
	import nl.wv.extenders.panel.SuperPanel;
	
	import tools.*;
	
	public class ViewMessage{
		private var panel:SuperPanel = new SuperPanel();
		private var tekst:TextArea = new TextArea();
		private var tool:Tool = new Tool();
		private var label1:Label = new Label();
		private var label2:Label = new Label();
		private var label3:Label = new Label();
		private var odgovori:Button = new Button();
		private var _username:String = "";
		public function ViewMessage(p:SuperPanel){
			panel = p;
			label1.x = 10;
			label1.y = 27;
			label1.width = panel.width-30;
			label1.height = 25;
			label2.x = 10;
			label2.y = 45;
			label2.width = panel.width-30;
			label2.height = 25;
			label3.x = 10;
			label3.y = 65;
			label3.width = panel.width-30;
			label3.height = 25;
			odgovori.label = "Odgovori";
			odgovori.x = panel.width-100;
			odgovori.y = panel.height-45;
			odgovori.enabled = false;
			tekst.x = 10;
			tekst.y = 85;
			tekst.height = panel.height-140;
	 		tekst.width=panel.width-30;
	 		tekst.editable = false;
			panel.addChild(tekst);
			panel.addChild(label1);
			panel.addChild(label2);
			panel.addChild(label3);
			panel.addChild(odgovori);
			panel.addEventListener(ResizeEvent.RESIZE, onResize);
			odgovori.addEventListener(MouseEvent.CLICK, onOdgovori);
		}
		
		public function onOdgovori(e:MouseEvent):void{
			if(!panel.parentApplication.checkExist("NOVA PORUKA")){
				var s:SuperPanel;
				panel.parentApplication.panels.push(s = tool.createPanel("NOVA PORUKA", 0, 400, 400, 50, 50, true, false, "NovaPoruka"));
				panel.parentApplication.addChild(s);
				s.backButton.addEventListener(MouseEvent.CLICK, panel.parentApplication.taskbarButtonClicked);
				s.backButton.addEventListener(MouseEvent.RIGHT_CLICK, panel.parentApplication.taskbarButtonRightClicked);
				var n:NewMessage = new NewMessage(s);
				n.defaultPrimaoc = _username;
			}
		}
		
		public function onResize(e:ResizeEvent):void{
	 		tekst.width=panel.width-30;
			label1.width = panel.width-30;
			label2.width = panel.width-30;
			label3.width = panel.width-30;
			tekst.height = panel.height-140;
			odgovori.x = panel.width-100;
			odgovori.y = panel.height-45;
		}
		
		public function show(naslov:String, username:String, fullPoruka:String, datumSlanja:String, vrijemeslanja:String, datumPrimanja:String, vrijemeprimanja:String):void{
			_username = username;
			label1.htmlText = "Autor: <b>"+username+"</b> dana: <b>"+datumSlanja+"</b> u <b>"+vrijemeslanja+"</b>";
			label3.htmlText = "Naslov: <b>"+naslov+"</b>";
			if(datumPrimanja.length>0) label2.htmlText = "Primaoc primio poruku dana: <b>"+datumPrimanja+"</b> u <b>"+vrijemeprimanja+"</b>";
				else label2.htmlText = "Primaoc nije primio poruku";
			tekst.htmlText = tool.DecodeTekst(fullPoruka);	
		}
		
		public function reply():void{
			odgovori.enabled = true;
		}
	}
}